//
//  DXEmotionAttachment.swift
//  weiBoOfSwift
//
//  Created by simon on 15/12/18.
//  Copyright © 2015年 simon. All rights reserved.
//

import UIKit

class DXEmotionAttachment: NSTextAttachment {
 
    var emotionModel:DXEmotonModel
    
    
     init(emotion:DXEmotonModel){
        emotionModel = emotion
         super.init(data: nil, ofType: nil)
     
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func getAttributString(font:UIFont)-> NSMutableAttributedString{
    image = UIImage(named: emotionModel.img!, inBundle: DXEmotionViewModel.sharedEmoton.EmotionBundel, compatibleWithTraitCollection: nil)
        
//    image = UIImage(named: emotionModel.img!)
   bounds = CGRect(x: 0, y: -3, width: font.lineHeight, height: font.lineHeight)
    //            由附件生成一个富文本
    let imgAttribut = NSAttributedString(attachment: self)
    let imgAttibutM =  NSMutableAttributedString(attributedString: imgAttribut)
    imgAttibutM.addAttributes([NSFontAttributeName:font], range: NSMakeRange(0, 1))
    
        return imgAttibutM
    }
    
    
}
